package com.tarena.lbs.article.web.controller;

import com.tarena.lbs.article.web.service.ArticleService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.content.param.ArticleActionParam;
import com.tarena.lbs.pojo.content.param.ArticleContentParam;
import com.tarena.lbs.pojo.content.query.ArticleQuery;
import com.tarena.lbs.pojo.content.vo.ArticleActionPageResultVO;
import com.tarena.lbs.pojo.content.vo.ArticleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;

@RestController
@Slf4j
public class ArticleController {
    //前台小程序 后台管理员 查询文章分页列表
    @Autowired
    private ArticleService articleService;
    @GetMapping("/admin/content/article/list")
    public Result<PageResult<ArticleVO>> articlePage(ArticleQuery articleQuery)
        throws BusinessException{
        return new Result<>(articleService.articlePage(articleQuery));
    }
    //新增提交 推文创作
    @PostMapping("/admin/content/article/insert")
    public Result<Void> addArticle(ArticleContentParam articleContentParam)
    throws BusinessException{
        articleService.addArticle(articleContentParam);
        return Result.success();
    }
    //统计查询 文章 标签集合
    @GetMapping("/admin/content/article/getArticleLabel")
    public Result<HashSet<String>> articleLabels(ArticleQuery articleQuery)
        throws BusinessException{
        return new Result<>(articleService.articleLabels(articleQuery));
    }
    //使用文档id查询文章索引数据的详情
    @GetMapping("/admin/content/article/get")
    public Result<ArticleVO> detail(Integer id)throws BusinessException{
        return new Result<>(articleService.detail(id));
    }
    //用户点赞或者收藏
    @PostMapping("/admin/content/article/behavior")
    public Result<Void> behavior(ArticleActionParam param)
        throws BusinessException{
        articleService.behavior(param);
        return Result.success();
    }
    //查询当前登录用户 曾经访问过 点赞过 收藏过的文章
    @GetMapping("/admin/content/article/getBehaviorList")
    public Result<ArticleActionPageResultVO> getActinList(ArticleQuery query)
        throws BusinessException{
        ArticleActionPageResultVO vo=articleService.getActionList(query);
        return new Result<>(vo);
    }

}
